<script setup lang="ts">
import { ref } from "vue"
import Index from "./components/index.vue"
import Round from "./components/round.vue"
import Tworounds from "./components/Tworounds.vue"
import Threerounds from "./components/Threerounds.vue"

const nvaList = ref<string[]>(["首页", "我好像在哪里见过你", "摩天大楼", "天外来物"])

const activeIndex = ref(1)
function changeTab(index: number) {
  activeIndex.value = index
  currentTab.value = ["Index", "Round", "Tworounds", "Threerounds"][index]
}

const currentTab = ref("Round")
type TabsItem = {
  Index: typeof Index
  Round: typeof Round
  Tworounds: typeof Tworounds
  Threerounds: typeof Threerounds
}
const tabs: TabsItem = {
  Index,
  Round,
  Tworounds,
  Threerounds
}
</script>

<template>
  <div class="top">
    <div class="header width flex">
      <img src="@/assets/img/logo.jpg" class="header_logo" alt="" />
      <h4>我开始找你了 天外来物</h4>
    </div>
    <div class="nav width">
      <span class="flex" v-for="(item, index) in nvaList" :key="index" @click="changeTab(index)">
        {{ item }}
        <!-- 游标 -->
        <view class="cursor" :style="{ left: activeIndex * 25 + '%' }"></view>
      </span>
    </div>
  </div>
  <KeepAlive>
    <component :is="tabs[currentTab as keyof TabsItem]" class="tab"></component>
  </KeepAlive>
</template>

<style scoped lang="scss">
.top {
  position: sticky;
  top: 0;
  left: 0;
  background: #fff;
  z-index: 9999999;
}
.header {
  height: 100px;
  justify-content: flex-start;
  &_logo {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    margin-right: 20px;
  }
  h4 {
    font-size: 30px;
  }
}
.nav {
  position: relative;
  display: flex;
  align-items: center;
  height: 60px;
  font-size: 22px;
  margin-bottom: 20px;
  span {
    flex: 1;
    cursor: pointer;
  }
  .cursor {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 5%;
    height: 6px;
    padding: 0 50px;
    background-color: $color;
    transform: translateX(100%);
    /* 过渡效果 */
    transition: all 0.4s;
  }
  span:hover {
    color: $color;
  }
}
</style>
